function loadServerData(url, data, render, loadingParent) {
    showLoading($(loadingParent));
    $.ajax({
        url: url,
        data: {
            datas: JSON.stringify(data)
        },
        dataType: "json",
        success: function (ret) {
            hideLoading($(loadingParent));
            render(ret);
        },
        error: function (ret) {
            alert("发生错误");
            hideLoading($(loadingParent));
            console.debug(ret);
        }
    });
}

function showLoading(parent) {
    if (parent.find(".loading").length == 0)
        parent.append($("<div class='loading'></div>"));
}

function hideLoading(parent) {
    parent.find(".loading").fadeOut(300, function () {
        $(this).remove();
    });
}

function getGroupObj(title) {
    return $(
        '<div class="group">' +
        '   <div class="groupName">' + title + '</div>' +
        '   <div class="groupContent">' +
        '   <table border="0" cellpadding="0" cellspacing="0"></table>' +
        '</div>' +
        '</div>'
    );
}

//审核
function checkCount() {
    loadServerData("/quality/check/queryCount", {}, function (data) {
        var all = data.datas[0].countAll;
        $("#newApply #countAll").html(all);
        if (all > 0)
            $("#apply").html("<div class='redPoint'>" + all + "</div>");
        else
            $("#apply").html("");
    });

    loadServerData("/quality/check/queryAll", {
        icheckflag: 0,
        pageNum: 1,
        today:0,
        error: true,
        pageSize: 10
    }, function (data) {

        loadPager(data.datas, "checkList1", [{
            data: "patname"
        }, {
            data: "cdeptname"
        }, {
            data: "csickname",
            hide: true
        }, {
            render: function (data) {
                var typeName="";
                if(data.iapplytypecode=="0001")
                    typeName="血制品申请";
                else if(data.iapplytypecode=="0002")
                    typeName="高值耗材申请";
                else if(data.iapplytypecode=="0003")
                    typeName="入单病种申请";
                else if(data.iapplytypecode=="0004")
                    typeName="出单病种申请";
                return typeName;
            }
        }], function (item) {
            showDetail([{
                text: "审核",
                click: function () {
                    if(item.iapplytypecode=="0002"){
                        top.addTabs({
                            id: "expensive"+item.iCheckid + "check",
                            title: item.patname + "-审核",
                            close: 'ture',
                            url: "/check/expensive/detail/check/" + item.iCheckid
                        });
                    }else{
                        alert("尚未开展！");
                    }

                }
            }
            // , {
            //     text: "驳回",
            //     click: function (data) {
            //         var reason = prompt("请输入驳回原因：");
            //         if (reason == null) {
            //             return;
            //         }
            //         else if (reason == "") {
            //             alert("驳回操作失败，必须输入驳回原因！");
            //         } else {
            //             $.ajax({
            //                 type: 'POST',
            //                 data: {
            //                     datas: JSON.stringify({
            //                         icheckid: item.iCheckid,
            //                         icheckflag: "2",
            //                         dopinion: reason
            //
            //                     })
            //                 },
            //                 url: '/index/check/checkSubmit/',
            //                 success: function (data) {
            //                     //成功之后
            //                     alert("操作成功！");
            //                     hideShade();
            //                     hideDetail();
            //                     checkCount();
            //                 },
            //                 error: function (xhr, type) {
            //                     alert("错误", "系统发生内部错误!请稍后再试!", "error");
            //                 }
            //             });
            //         }
            //     }
            // }
            ]);
            $(".detailWindow .title").html("审核详情");
            $(".detailWindow .subTitle").html("就诊人：" + item.patname + "<span>省医保</span>");
            $(".detailWindow .detailBody .ruleInfo").html("<table border=0 cellpadding=0 cellspacing=0></table>");
            // $(".detailWindow .detailBody .ruleInfo").append("<div class='ruleTitle'>就诊人信息</div>");
            var tr3 = $("<tr></tr>");
            $(".detailWindow .detailBody .ruleInfo table").append(tr3);
            tr3.append("<td>申请科室：</td><td>" + item.iapplydeptname + "</td><td>申请时间：</td><td colspan='5'>" + item.dapplydate + "</td>");
            var tr1 = $("<tr></tr>");
            $(".detailWindow .detailBody .ruleInfo table").append(tr1);
            tr1.append("<td>所属科室：</td><td>" + item.cdeptname + "</td><td>诊断疾病：</td><td colspan='5'>" + item.csickname + "</td>");

            clearDetailWindow();
            var tableGroup = $("<div class='tableGroups'></div>");
            $(".detailWindow .detailBody").append(tableGroup);
            //费用明细
            var group = getGroupObj("申请内容");
            tableGroup.append(group);
            loadServerData("/quality/check/queryDetailList/" + item.iCheckid, null, function (data) {
                for (var i = 0; i < data.datas.length;) {
                    var tr = $("<tr></tr>");
                    group.find("table").append(tr);
                    for (var j = 0; j < 1; j++) {
                        if (i < data.datas.length) {
                            tr.append($("<td>" + data.datas[i].itemname +
                                "</td><td>单位：" + data.datas[i].unit +
                                "</td><td>数量：" + data.datas[i].num +
                                "</td>"));
                            i++;
                        } else {
                            break;
                        }
                    }
                }
            })
        });
    });

    loadServerData("/quality/check/queryAll", {
        icheckflag: '1,2',
        pageNum: 1,
        today:1,
        error: true,
        pageSize: 10
    }, function (data) {
        loadPager(data.datas, "checkList2", [{
            data: "patname"
        }, {
            data: "cdeptname"
        }, {
            data: "csickname",
            hide: true
        }, {
            render: function (data) {
                var typeName="";
                if(data.iapplytypecode=="0001")
                    typeName="血制品申请";
                else if(data.iapplytypecode=="0002")
                    typeName="高值耗材申请";
                else if(data.iapplytypecode=="0003")
                    typeName="入单病种申请";
                else if(data.iapplytypecode=="0004")
                    typeName="出单病种申请";
                return typeName;
            }
        }, {
            render: function (data) {
                if (data.icheckflag == "1")
                    return "<span class='am-icon-check-circle-o' style='color:#27a3e5;background-color: #c9e4f3'>审核通过</span>"
                else if (data.icheckflag == "2")
                    return "<span class='am-icon-close' style='color:#dd3a5f;background-color: #fdd9e1'>已经驳回</span>"
                else if (data.icheckflag == "3")
                    return "免审核"
            }
        }], function (item) {
            showDetail();
            $(".detailWindow .title").html("审核详情");
            $(".detailWindow .subTitle").html("就诊人：" + item.patname + "<span>" + item.patienttype + "</span>" + "<span class='am-icon-internet-explorer' style='background-color: #3794cb'><a style='color:#fff' target='_blank' href='" + Url360 + "?id=" + item.no_treatlist + "'> 详细病历</a></span>");
            $(".detailWindow .detailBody .ruleInfo").html("<table border=0 cellpadding=0 cellspacing=0></table>");
            if (item.icheckflag == "2") $(".detailWindow .detailFoot .info").append("驳回原因：" + (item.dopinion || "无"));
            if (item.icheckflag == "1") $(".detailWindow .detailFoot .info").append("审核通过");
            var tr3 = $("<tr></tr>");
            $(".detailWindow .detailBody .ruleInfo table").append(tr3);
            tr3.append("<td>申请科室：</td><td>" + item.iapplydeptname + "</td><td>申请时间：</td><td colspan='5'>" + item.dapplydate + "</td>");
            var tr1 = $("<tr></tr>");
            $(".detailWindow .detailBody .ruleInfo table").append(tr1);
            tr1.append("<td>所属科室：</td><td>" + item.cdeptname + "</td><td>诊断疾病：</td><td colspan='5'>" + item.csickname + "</td>");

            clearDetailWindow();
            var tableGroup = $("<div class='tableGroups'></div>");
            $(".detailWindow .detailBody").append(tableGroup);
            //费用明细
            var group = getGroupObj("申请内容");
            tableGroup.append(group);
            loadServerData("/quality/dayoperation/queryDetailList/" + item.PatientId, null, function (data) {
                for (var i = 0; i < data.datas.length;) {
                    var tr = $("<tr></tr>");
                    group.find("table").append(tr);
                    for (var j = 0; j < 1; j++) {
                        if (i < data.datas.length) {
                            tr.append($("<td>血制品：" + "血浆" +
                                "</td><td>单位：" + "200ml" +
                                "</td><td>数量：" + "1" +
                                "</td>"));
                            i++;
                        } else {
                            break;
                        }
                    }
                }
            })
        });
    });

}

//总额
function zeCount() {
    var now = new Date();
    var year = now.getFullYear();
    var month = now.getMonth() * 1 + 1;
    loadServerData("/quality/total/queryAll/1/" + year + "-1-1/" + year + "-12-31", {}, function (data) {
        var money = data.datas[0].TcMoney;
        var ms = money.toFixed(2);
        ms = parseFloat(ms)
        ms = ms.toLocaleString();
        $("#totalBar1 #yearV").html("已使用总额￥" + ms);
        $("#totalBar1 #yearV").attr("title", "已使用总额￥" + ms);
        $("#totalBar1 #yearV").attr("val", money);
        $("#totalBar1 #yearV").css("min-width", "calc(" + money / totalData.medA.ZE.ZE1 * 50 + "% + 0.8em)");
        $("#totalBar1 #yearB").css("width", money / totalData.medA.ZE.ZE1 * 50 + "%");
    });
    loadServerData("/quality/total/queryAll/1/" + year + "-" + month + "-1/" + year + "-12-31", {}, function (data) {
        var money = data.datas[0].TcMoney;
        var ms = money.toFixed(2);
        ms = parseFloat(ms)
        ms = ms.toLocaleString();
        $("#totalBar1 #monthV").html("本月使用￥" + ms);
        $("#totalBar1 #monthV").attr("title", "本月使用￥" + ms);
        $("#totalBar1 #monthB").css("width", money / totalData.medA.ZE.ZE1 * 50 + "%");
    });

    loadServerData("/quality/total/queryAll/2/" + year + "-1-1/" + year + "-12-31", {}, function (data) {
        var money = data.datas[0].TcMoney;
        var ms = money.toFixed(2);
        ms = parseFloat(ms)
        ms = ms.toLocaleString();
        $("#totalBar2 #yearV").html("已使用总额￥" + ms);
        $("#totalBar2 #yearV").attr("title", "已使用总额￥" + ms);
        $("#totalBar2 #yearV").attr("val", money);
        $("#totalBar2 #yearV").css("min-width", "calc(" + money / totalData.medB.ZE.ZE1 * 50 + "% + 0.8em)");
        $("#totalBar2 #yearB").css("width", money / totalData.medB.ZE.ZE1 * 50 + "%");
    });
    loadServerData("/quality/total/queryAll/2/" + year + "-" + month + "-1/" + year + "-12-31", {}, function (data) {
        var money = data.datas[0].TcMoney;
        var ms = money.toFixed(2);
        ms = parseFloat(ms)
        ms = ms.toLocaleString();
        $("#totalBar2 #monthV").html("本月使用￥" + ms);
        $("#totalBar2 #monthV").attr("title", "本月使用￥" + money);
        $("#totalBar2 #monthB").css("width", money / totalData.medB.ZE.ZE1 * 50 + "%");
    });

    $("#totalBar1").on("click", function () {
        showDetail();
        $(".detailWindow .title").html("总额质控");
        $(".detailWindow .subTitle").html("省医保");
        $(".detailWindow .detailBody .ruleInfo").html("<table border=0 cellpadding=0 cellspacing=0></table>");
        var tr2 = $("<tr></tr>");
        $(".detailWindow .detailBody .ruleInfo table").append(tr2);
        tr2.append("<td width='100'>医保总额</td>" +
            "<td width='100'>" + totalData.medA.ZE.ZE1 + "</td>" +
            "<td width='100'>已使用总额</td>" +
            "<td width='100'>" + $("#totalBar1 #yearV").attr("val") + "</td>" +
            "<td width='100'>使用占比</td>" +
            "<td width='100'> " + ($("#totalBar1 #yearV").attr("val") / totalData.medA.ZE.ZE1 * 100).toFixed(2) + "%</td>");
        clearDetailWindow();
        var tableGroup = $("<div class='tableGroups'></div>");
        $(".detailWindow .detailBody").append(tableGroup);
        //科室明细
        var group = getGroupObj("科室明细");
        tableGroup.append(group);
        var now = new Date();
        var year = now.getFullYear();
        loadServerData("/quality/total/queryDetailList/1/" + year + "-1-1/" + year + "-12-31", {}, function (data) {
            for (var i = 0; i < data.datas.length;) {
                var tr = $("<tr></tr>");
                group.find("table").append(tr);
                for (var j = 0; j < 1; j++) {
                    if (i < data.datas.length) {
                        tr.append($("<td>" + data.datas[i].DeptName +
                            "</td><td>本年总金额：" + data.datas[i].TcMoney +
                            "</td><td>全院使用占比：" + (data.datas[i].TcMoney / $("#totalBar1 #yearV").attr("val") * 100).toFixed(2) + "%" +
                            "</td><td>医保总额占比：" + (data.datas[i].TcMoney / totalData.medA.ZE.ZE1 * 100).toFixed(2) + "%" +
                            "</td>"));
                        i++;
                    } else {
                        break;
                    }
                }
            }
        })
    })

    $("#totalBar2").on("click", function () {
        showDetail();
        $(".detailWindow .title").html("总额质控");
        $(".detailWindow .subTitle").html("市医保");
        $(".detailWindow .detailBody .ruleInfo").html("<table border=0 cellpadding=0 cellspacing=0></table>");
        var tr2 = $("<tr></tr>");
        $(".detailWindow .detailBody .ruleInfo table").append(tr2);
        tr2.append("<td width='100'>医保总额</td>" +
            "<td width='100'>" + totalData.medB.ZE.ZE1 + "</td>" +
            "<td width='100'>已使用总额</td>" +
            "<td width='100'>" + $("#totalBar2 #yearV").attr("val") + "</td>" +
            "<td width='100'>使用占比</td>" +
            "<td width='100'> " + ($("#totalBar2 #yearV").attr("val") / totalData.medB.ZE.ZE1 * 100).toFixed(2) + "%</td>");
        clearDetailWindow();
        var tableGroup = $("<div class='tableGroups'></div>");
        $(".detailWindow .detailBody").append(tableGroup);
        //科室明细
        var group = getGroupObj("科室明细");
        tableGroup.append(group);
        var now = new Date();
        var year = now.getFullYear();
        loadServerData("/quality/total/queryDetailList/2/" + year + "-1-1/" + year + "-12-31", {}, function (data) {
            for (var i = 0; i < data.datas.length;) {
                var tr = $("<tr></tr>");
                group.find("table").append(tr);
                for (var j = 0; j < 1; j++) {
                    if (i < data.datas.length) {
                        tr.append($("<td>" + data.datas[i].DeptName +
                            "</td><td>本年总金额：" + data.datas[i].TcMoney +
                            "</td><td>全院使用占比：" + (data.datas[i].TcMoney / $("#totalBar2 #yearV").attr("val") * 100).toFixed(2) + "%" +
                            "</td><td>医保总额占比：" + (data.datas[i].TcMoney / totalData.medB.ZE.ZE1 * 100).toFixed(2) + "%" +
                            "</td>"));
                        i++;
                    } else {
                        break;
                    }
                }
            }
        })
    })

}

//日间手术
function rjssCount() {
    loadServerData("/quality/dayoperation/queryCount/1/0", {}, function (data) {
        var error1 = data.datas[0].countError;
        var all1 = data.datas[0].countAll;
        $("#rjss #error1").html(error1);
        $("#rjss #all1").html(all1);
        $("#rjss #sumError").html($("#rjss #error1").html() * 1 + $("#rjss #error2").html() * 1);
        $("#rjss #sumAll").html($("#rjss #all1").html() * 1 + $("#rjss #all2").html() * 1);
        $("#rjss .infoBar").css("width", $("#rjss #sumError").html() / $("#rjss #sumAll").html() * 100 + "%");
        $("#rjss .listBar").css("width", $("#rjss #sumError").html() / $("#rjss #sumAll").html() * 100 + "%");
    });
    loadServerData("/quality/dayoperation/queryCount/2/0", {}, function (data) {
        var error2 = data.datas[0].countError;
        var all2 = data.datas[0].countAll;
        $("#rjss #error2").html(error2);
        $("#rjss #all2").html(all2);
        $("#rjss #sumError").html($("#rjss #error1").html() * 1 + $("#rjss #error2").html() * 1);
        $("#rjss #sumAll").html($("#rjss #all1").html() * 1 + $("#rjss #all2").html() * 1);
        $("#rjss .infoBar").css("width", $("#rjss #sumError").html() / $("#rjss #sumAll").html() * 100 + "%");
        $("#rjss .listBar").css("width", $("#rjss #sumError").html() / $("#rjss #sumAll").html() * 100 + "%");
    });
    $("#rjss .more").bind("click", function () {
        top.addTabs({
            id: "rjssZK",
            title: "日间手术质控",
            close: true,
            url: "/quality/dayoperation"
        })
    });


    loadServerData("/quality/dayoperation/queryAllPager", {
        ybType: 1,
        pageNum: 1,
        error: true,
        pageSize: 10
    }, function (data) {


        loadPager(data.datas, "rjList1", [{
            data: "DeptName"
        }, {
            data: "Name"
        }, {
            hide: true,
            data: "Icd10Name"
        }, {
            render: function (item) {
                return item.InMoney + "元";
            }
        }, {
            render: function (item) {
                return item.InDays + "天 <span class='hide am-icon-flag' style='background:#fbf2ec'>" + item.Stddays + "天</span>";
            }
        }], function (item) {
            showDetail();
            $(".detailWindow .title").html("日间手术质控");
            $(".detailWindow .subTitle").html("就诊人姓名：" + item.Name + "<span>省医保</span>");
            $(".detailWindow .detailBody .ruleInfo").html("<table border=0 cellpadding=0 cellspacing=0></table>");
            // $(".detailWindow .detailBody .ruleInfo").append("<div class='ruleTitle'>就诊人信息</div>");
            var tr2 = $("<tr></tr>");
            $(".detailWindow .detailBody .ruleInfo table").append(tr2);
            tr2.append("<td width='100'>累计费用：</td>" +
                "<td width='100'>" + item.InMoney + "</td>" +
                "<td width='100'>标准费用：</td>" +
                "<td width='100'>" + item.StdMoney + "</td>" +
                "<td width='100'>住院天数：</td>" +
                "<td width='100'>" + item.InDays + "</td>" +
                "<td width='100'>标准天数：</td>" +
                "<td width='100'>" + item.Stddays + "</td>");
            var tr3 = $("<tr></tr>");
            $(".detailWindow .detailBody .ruleInfo table").append(tr3);
            tr3.append("<td>主治医生：</td><td>" + item.Doctorname + "</td><td>违规时间：</td><td colspan='5'>" + item.CreateDate + "</td>");
            var tr1 = $("<tr></tr>");
            $(".detailWindow .detailBody .ruleInfo table").append(tr1);
            tr1.append("<td>所属科室：</td><td>" + item.DeptName + "</td><td>诊断疾病：</td><td colspan='5'>" + item.Icd10Name + "</td>");

            clearDetailWindow();
            var tableGroup = $("<div class='tableGroups'></div>");
            $(".detailWindow .detailBody").append(tableGroup);
            //费用明细
            var group = getGroupObj("违规明细");
            tableGroup.append(group);
            loadServerData("/quality/dayoperation/queryDetailList/" + item.PatientId, null, function (data) {
                for (var i = 0; i < data.datas.length;) {
                    var tr = $("<tr></tr>");
                    group.find("table").append(tr);
                    for (var j = 0; j < 1; j++) {
                        if (i < data.datas.length) {
                            tr.append($("<td>总金额：" + data.datas[i].nmoney +
                                "</td><td>定额：" + data.datas[i].nfixedmoney +
                                "</td><td>" + data.datas[i].intime +
                                "</td><td>" + "超过标准天数" +
                                "</td><td>" + "医生已阅读并同意执行" +
                                "</td>"));
                            i++;
                        } else {
                            break;
                        }
                    }
                }
            })
        });

    });
    loadServerData("/quality/dayoperation/queryAllPager", {
        ybType: 2,
        pageNum: 1,
        error: true,
        pageSize: 10
    }, function (data) {


        loadPager(data.datas, "rjList2", [{
            data: "DeptName"
        }, {
            data: "Name"
        }, {
            hide: true,
            data: "Icd10Name"
        }, {
            render: function (item) {
                return item.InMoney + "元";
            }
        }, {
            render: function (item) {
                return item.InDays + "天 <span class='hide am-icon-flag' style='background:#fbf2ec'>" + item.Stddays + "天</span>";
            }
        }], function (item) {
            showDetail();
            $(".detailWindow .title").html("日间手术质控");
            $(".detailWindow .subTitle").html("就诊人姓名：" + item.Name + "<span>市医保</span>");
            $(".detailWindow .detailBody .ruleInfo").html("<table border=0 cellpadding=0 cellspacing=0></table>");
            // $(".detailWindow .detailBody .ruleInfo").append("<div class='ruleTitle'>就诊人信息</div>");
            var tr2 = $("<tr></tr>");
            $(".detailWindow .detailBody .ruleInfo table").append(tr2);
            tr2.append("<td width='100'>累计费用：</td>" +
                "<td width='100'>" + item.InMoney + "</td>" +
                "<td width='100'>标准费用：</td>" +
                "<td width='100'>" + item.StdMoney + "</td>" +
                "<td width='100'>住院天数：</td>" +
                "<td width='100'>" + item.InDays + "</td>" +
                "<td width='100'>标准天数：</td>" +
                "<td width='100'>" + item.Stddays + "</td>");
            var tr3 = $("<tr></tr>");
            $(".detailWindow .detailBody .ruleInfo table").append(tr3);
            tr3.append("<td>主治医生：</td><td>" + item.Doctorname + "</td><td>违规时间：</td><td colspan='5'>" + item.CreateDate + "</td>");
            var tr1 = $("<tr></tr>");
            $(".detailWindow .detailBody .ruleInfo table").append(tr1);
            tr1.append("<td>所属科室：</td><td>" + item.DeptName + "</td><td>诊断疾病：</td><td colspan='5'>" + item.Icd10Name + "</td>");

            clearDetailWindow();
            var tableGroup = $("<div class='tableGroups'></div>");
            $(".detailWindow .detailBody").append(tableGroup);
            //费用明细
            var group = getGroupObj("违规明细");
            tableGroup.append(group);
            loadServerData("/quality/dayoperation/queryDetailList/" + item.PatientId, null, function (data) {
                for (var i = 0; i < data.datas.length;) {
                    var tr = $("<tr></tr>");
                    group.find("table").append(tr);
                    for (var j = 0; j < 1; j++) {
                        if (i < data.datas.length) {
                            tr.append($("<td>总金额：" + data.datas[i].nmoney +
                                "</td><td>定额：" + data.datas[i].nfixedmoney +
                                "</td><td>" + data.datas[i].intime +
                                "</td><td>" + "超过标准天数" +
                                "</td><td>" + "医生已阅读并同意执行" +
                                "</td>"));
                            i++;
                        } else {
                            break;
                        }
                    }
                }
            })
        });

    });

}

//贫困人口
function pkrkCount() {
    var boxId = "#pkrk";
    loadServerData("/quality/poor/queryCount/1/0", {}, function (data) {
        var error1 = data.datas[0].countError;
        var all1 = data.datas[0].countAll;
        $(boxId + " #error1").html(error1);
        $(boxId + " #all1").html(all1);
        $(boxId + " #sumError").html($(boxId + " #error1").html() * 1 + $(boxId + " #error2").html() * 1);
        $(boxId + " #sumAll").html($(boxId + " #all1").html() * 1 + $(boxId + " #all2").html() * 1);
        $(boxId + " .infoBar").css("width", $(boxId + " #sumError").html() / $(boxId + " #sumAll").html() * 100 + "%");
        $(boxId + " .listBar").css("width", $(boxId + " #sumError").html() / $(boxId + " #sumAll").html() * 100 + "%");
    }, boxId + " #error1");
    loadServerData("/quality/poor/queryCount/2/0", {}, function (data) {
        var error2 = data.datas[0].countError;
        var all2 = data.datas[0].countAll;
        $(boxId + " #error2").html(error2);
        $(boxId + " #all2").html(all2);
        $(boxId + " #sumError").html($(boxId + " #error1").html() * 1 + $(boxId + " #error2").html() * 1);
        $(boxId + " #sumAll").html($(boxId + " #all1").html() * 1 + $(boxId + " #all2").html() * 1);
        $(boxId + " .infoBar").css("width", $(boxId + " #sumError").html() / $(boxId + " #sumAll").html() * 100 + "%");
        $(boxId + " .listBar").css("width", $(boxId + " #sumError").html() / $(boxId + " #sumAll").html() * 100 + "%");
    }, boxId + " #error2");
    $(boxId + " .more").bind("click", function () {
        top.addTabs({
            id: "pkrkZK",
            title: "贫困就诊人质控",
            close: true,
            url: "/quality/poor"
        })
    });
    loadServerData("/quality/poor/queryAllPager", {
        ybType: 1,
        pageNum: 1,
        error: true,
        onlyOver: onlyOver,
        pageSize: 10
    }, function (data) {


        loadPager(data.datas, "pkList1", [{
            data: "DeptName",
            render: function (data) {
                return data.DeptName.substr(0, 12);
            }
        }, {
            data: "Name"
        }, {
            hide: true,
            data: "Icd10Name",
            render: function (data) {
                return data.Icd10Name.substr(0, 25);
            }
        }, {
            render: function (data) {
                return data.InMoney + "元";
            }
        }, {
            render: function (item) {
                if (item.Blbl > 0.3) {
                    return "<span style='background-color:orangered;font-weight: 800; color:#fff;'>" + (item.Blbl * 100).toFixed(2) + "%</span>";
                } else {
                    return "<span style='background-color:#000000;color:#fff;'>" + (item.Blbl * 100).toFixed(2) + "%</span>";
                }

            }
        }], function (item) {
            showDetail();
            $(".detailWindow .title").html("贫困就诊人质控");
            $(".detailWindow .subTitle").html("就诊人姓名：" + item.Name + "<span>" + item.PatientTypeName + "</span>");
            $(".detailWindow .detailBody .ruleInfo").html("<table border=0 cellpadding=0 cellspacing=0></table>");
            // $(".detailWindow .detailBody .ruleInfo").append("<div class='ruleTitle'>就诊人信息</div>");
            var tr2 = $("<tr></tr>");
            $(".detailWindow .detailBody .ruleInfo table").append(tr2);
            tr2.append("<td width='100'>就诊号：</td>" +
                "<td width='100'>" + item.PatientId + "</td>" +
                "<td width='100'>累计费用总额：</td>" +
                "<td width='100' id='InMoney'>" + item.InMoney + " </td>" +
                "<td width='100'>丙类费用总额：</td>" +
                "<td width='100' id='blmoney'>" + item.blmoney + "</td>" +
                "<td width='100'>丙类占比：</td>" +
                "<td width='100' id='Blbl'> " + (item.Blbl * 100).toFixed(2) + "%</td>");
            var tr3 = $("<tr></tr>");
            $(".detailWindow .detailBody .ruleInfo table").append(tr3);
            tr3.append("<td>住院号：</td><td>" + item.inpcode + "</td><td>主治医生：</td><td>" + item.Doctorname + "</td><td>入院时间：</td><td colspan='3'>" + item.dinhos + "</td>");
            var tr1 = $("<tr></tr>");
            $(".detailWindow .detailBody .ruleInfo table").append(tr1);
            tr1.append("<td>所属科室：</td><td>" + item.DeptName + "</td><td>诊断疾病：</td><td colspan='5'>" + item.Icd10Name + "</td>");

            clearDetailWindow();
            var tableGroup = $("<div class='tableGroups'></div>");
            $(".detailWindow .detailBody").append(tableGroup);
            //费用明细
            var group = getGroupObj("科室丙类费用统计");
            tableGroup.append(group);
            loadServerData("/quality/poor/queryDeptList/" + item.PatientId, null, function (data) {
                for (var i = 0; i < data.datas.length;) {
                    var tr = $("<tr></tr>");
                    group.find("table").append(tr);
                    for (var j = 0; j < 1; j++) {
                        if (i < data.datas.length) {
                            tr.append($("<td>" + data.datas[i].DeptName +
                                "</td><td>丙类金额：" + data.datas[i].BlMoney +
                                "</td><td>总金额：" + data.datas[i].TotalMoney +
                                "</td><td>丙类占比：" + (data.datas[i].BlMoney / data.datas[i].TotalMoney * 100).toFixed(2) + "%" +
                                "</td>"));
                            i++;
                        } else {
                            break;
                        }
                    }
                }
            })

            var tableGroup1 = $("<div class='tableGroups'></div>");
            $(".detailWindow .detailBody").append(tableGroup1);
            var group1 = getGroupObj("甲类费用");
            tableGroup1.append(group1);
            loadServerData("/quality/poor/queryPKFareDetail/" + item.PatientId + "/1", null, function (data) {
                for (var i = 0; i < data.datas.length;) {
                    var tr = $("<tr></tr>");
                    group1.find("table").append(tr);
                    for (var j = 0; j < 1; j++) {
                        if (i < data.datas.length) {
                            tr.append($("<td>" + data.datas[i].DeptName +
                                "</td><td>" + data.datas[i].FareItemName +
                                "</td><td>金额：" + (data.datas[i].InMoney / data.datas[i].Quantity).toFixed(2) +
                                "</td><td>×" + data.datas[i].Quantity.toFixed(0) + "" +
                                "</td><td>" + (data.datas[i].InMoney).toFixed(2) + "" +
                                "</td>"));
                            i++;
                        } else {
                            break;
                        }
                    }
                }
            })

            var tableGroup2 = $("<div class='tableGroups'></div>");
            $(".detailWindow .detailBody").append(tableGroup2);
            var group2 = getGroupObj("乙类费用");
            tableGroup2.append(group2);
            loadServerData("/quality/poor/queryPKFareDetail/" + item.PatientId + "/2", null, function (data) {
                for (var i = 0; i < data.datas.length;) {
                    var tr = $("<tr></tr>");
                    group2.find("table").append(tr);
                    for (var j = 0; j < 1; j++) {
                        if (i < data.datas.length) {
                            tr.append($("<td>" + data.datas[i].DeptName +
                                "</td><td>" + data.datas[i].FareItemName +
                                "</td><td>金额：" + (data.datas[i].InMoney / data.datas[i].Quantity).toFixed(2) +
                                "</td><td>×" + data.datas[i].Quantity.toFixed(0) + "" +
                                "</td><td>" + (data.datas[i].InMoney).toFixed(2) + "" +
                                "</td>"));
                            i++;
                        } else {
                            break;
                        }
                    }
                }
            })
            var tableGroup3 = $("<div class='tableGroups'></div>");
            $(".detailWindow .detailBody").append(tableGroup3);
            $(".detailWindow .detailFoot .info").html("删除丙类金额：<span id='selectValue'>0.00</span> 转换丙类金额：<span id='replyValue'>0.00</span>");
            var group3 = getGroupObj("丙类费用");
            tableGroup3.append(group3);
            loadServerData("/quality/poor/queryPKFareDetail/" + item.PatientId + "/3", null, function (data) {
                for (var i = 0; i < data.datas.length;) {
                    var tr = $("<tr value='" + (data.datas[i].InMoney) + "'></tr>");
                    group3.find("table").append(tr);
                    for (var j = 0; j < 1; j++) {
                        if (i < data.datas.length) {
                            tr.append($("<td>" + data.datas[i].DeptName +
                                "</td><td>" + data.datas[i].FareItemName +
                                "</td><td>金额：" + (data.datas[i].InMoney / data.datas[i].Quantity).toFixed(2) +
                                "</td><td>×" + data.datas[i].Quantity.toFixed(0) + "" +
                                "</td><td>" + (data.datas[i].InMoney).toFixed(2) + "" +
                                "</td><td><span class='am-icon-reply myLink' id='reply'> 转换为甲类</span>" +
                                "</td>"));
                            i++;
                        } else {
                            break;
                        }
                    }
                    tr.on("click", function (e) {
                        var row = $(e.target).parents("tr");
                        var val = row.attr("value");
                        if (val == null) return;
                        if (row.hasClass("replyRow")){
                            var span=row.find("#reply");
                            span.html(" 转换为甲类")
                            span.removeClass("am-icon-share");
                            span.addClass("am-icon-reply");
                            row.removeClass("replyRow");
                            val *= -1;
                            var InMoney = $(".detailWindow .detailBody #InMoney");
                            var blmoney = $(".detailWindow .detailBody #blmoney");
                            var Blbl = $(".detailWindow .detailBody #Blbl");
                            var replyValueD = $(".detailWindow .detailFoot #replyValue");
                            var inM = InMoney.html().trim();
                            var blM = blmoney.html().trim();
                            var replyValue = replyValueD.html().trim();
                            blM = blM * 1 - (val * 1);
                            inM = inM * 1 ;
                            replyValue = replyValue * 1 + (val * 1);
                            blmoney.html((blM).toFixed(2)).css({
                                "font-weight": "800",
                                "color": "#c30303",
                                "font-size": "1.2em"
                            });
                            InMoney.html((inM).toFixed(2)).css({
                                "font-weight": "800",
                                "color": "#c30303",
                                "font-size": "1.2em"
                            });
                            Blbl.html(((blM / inM) * 100).toFixed(2) + "%").css({
                                "font-weight": "800",
                                "color": "#c30303",
                                "font-size": "1.2em"
                            });
                            $(".detailWindow .detailFoot #replyValue").html( replyValue.toFixed(2) );
                            val *= -1;
                        }
                        if (row.attr("delete") == "1") {
                            row.attr("delete", "0");
                            row.removeClass("deleteRow");
                            val *= -1;
                        } else {
                            row.attr("delete", "1");
                            row.addClass("deleteRow");
                            val *= 1;
                        }
                        var InMoney = $(".detailWindow .detailBody #InMoney");
                        var blmoney = $(".detailWindow .detailBody #blmoney");
                        var Blbl = $(".detailWindow .detailBody #Blbl");
                        var selectValueD = $(".detailWindow .detailFoot #selectValue");
                        var inM = InMoney.html().trim();
                        var blM = blmoney.html().trim();
                        var selectValue = selectValueD.html().trim();
                        blM = blM * 1 - (val * 1);
                        inM = inM * 1 - (val * 1);
                        selectValue = selectValue * 1 + (val * 1);
                        blmoney.html((blM).toFixed(2)).css({
                            "font-weight": "800",
                            "color": "#c30303",
                            "font-size": "1.2em"
                        });
                        InMoney.html((inM).toFixed(2)).css({
                            "font-weight": "800",
                            "color": "#c30303",
                            "font-size": "1.2em"
                        });
                        Blbl.html(((blM / inM) * 100).toFixed(2) + "%").css({
                            "font-weight": "800",
                            "color": "#c30303",
                            "font-size": "1.2em"
                        });
                        $(".detailWindow .detailFoot #selectValue").html( selectValue.toFixed(2) );


                    })

                    tr.on("click", "#reply", function (e) {
                        var row = $(e.target).parents("tr");
                        var val = row.attr("value");
                        if (val == null) return;
                        //如果已经是删除的数据则恢复为正常数据
                        if (row.attr("delete") == "1") {
                            row.attr("delete", "0");
                            row.removeClass("deleteRow");
                            val *= -1;
                            var InMoney = $(".detailWindow .detailBody #InMoney");
                            var blmoney = $(".detailWindow .detailBody #blmoney");
                            var Blbl = $(".detailWindow .detailBody #Blbl");
                            var selectValueD = $(".detailWindow .detailFoot #selectValue");
                            var inM = InMoney.html().trim();
                            var blM = blmoney.html().trim();
                            var selectValue = selectValueD.html().trim();
                            blM = blM * 1 - (val * 1);
                            inM = inM * 1 - (val * 1);
                            selectValue = selectValue * 1 + (val * 1);
                            blmoney.html((blM).toFixed(2)).css({
                                "font-weight": "800",
                                "color": "#c30303",
                                "font-size": "1.2em"
                            });
                            InMoney.html((inM).toFixed(2)).css({
                                "font-weight": "800",
                                "color": "#c30303",
                                "font-size": "1.2em"
                            });
                            Blbl.html(((blM / inM) * 100).toFixed(2) + "%").css({
                                "font-weight": "800",
                                "color": "#c30303",
                                "font-size": "1.2em"
                            });
                            $(".detailWindow .detailFoot #selectValue").html( selectValue.toFixed(2) );
                            val *= -1;
                        }
                        var span=$(e.target);
                        if(span.hasClass("am-icon-reply")){
                            span.html(" 恢复为丙类")
                            span.removeClass("am-icon-reply");
                            span.addClass("am-icon-share");
                            val *= 1;
                            row.addClass("replyRow");
                        }else{
                            span.html(" 转换为甲类")
                            span.removeClass("am-icon-share");
                            span.addClass("am-icon-reply");
                            val *= -1;
                            row.removeClass("replyRow");
                        }

                        var InMoney = $(".detailWindow .detailBody #InMoney");
                        var blmoney = $(".detailWindow .detailBody #blmoney");
                        var Blbl = $(".detailWindow .detailBody #Blbl");
                        var replyValueD = $(".detailWindow .detailFoot #replyValue");
                        var inM = InMoney.html().trim();
                        var blM = blmoney.html().trim();
                        var replyValue = replyValueD.html().trim();
                        blM = blM * 1 - (val * 1);
                        inM = inM * 1 ;
                        replyValue = replyValue * 1 + (val * 1);
                        blmoney.html((blM).toFixed(2)).css({
                            "font-weight": "800",
                            "color": "#c30303",
                            "font-size": "1.2em"
                        });
                        InMoney.html((inM).toFixed(2)).css({
                            "font-weight": "800",
                            "color": "#c30303",
                            "font-size": "1.2em"
                        });
                        Blbl.html(((blM / inM) * 100).toFixed(2) + "%").css({
                            "font-weight": "800",
                            "color": "#c30303",
                            "font-size": "1.2em"
                        });
                        $(".detailWindow .detailFoot #replyValue").html( replyValue.toFixed(2) );

                        e.stopPropagation();
                    })
                }
            })
            setTabPage([tableGroup, tableGroup1, tableGroup2, tableGroup3]);
        });

    }, "#pkList1");

    loadServerData("/quality/poor/queryAllPager", {
        ybType: 2,
        pageNum: 1,
        error: true,
        onlyOver: onlyOver,
        pageSize: 10
    }, function (data) {


        loadPager(data.datas, "pkList2", [{
            data: "DeptName",
            render: function (data) {
                return data.DeptName.substr(0, 12);
            }
        }, {
            data: "Name"
        }, {
            hide: true,
            data: "Icd10Name",
            render: function (data) {
                return data.Icd10Name.substr(0, 25);
            }
        }, {
            render: function (data) {
                return data.InMoney + "元";
            }
        }, {
            render: function (item) {
                if (item.Blbl > 0.3) {
                    return "<span style='background-color:orangered;font-weight: 800; color:#fff;'>" + (item.Blbl * 100).toFixed(2) + "%</span>";
                } else {
                    return "<span style='background-color:#000000;color:#fff;'>" + (item.Blbl * 100).toFixed(2) + "%</span>";
                }
            }
        }], function (item) {
            showDetail();
            $(".detailWindow .title").html("贫困就诊人质控");
            $(".detailWindow .subTitle").html("就诊人姓名：" + item.Name + "<span>" + item.PatientTypeName + "</span>");
            $(".detailWindow .detailBody .ruleInfo").html("<table border=0 cellpadding=0 cellspacing=0></table>");
            // $(".detailWindow .detailBody .ruleInfo").append("<div class='ruleTitle'>就诊人信息</div>");
            var tr2 = $("<tr></tr>");
            $(".detailWindow .detailBody .ruleInfo table").append(tr2);
            tr2.append("<td width='100'>就诊号：</td>" +
                "<td width='100'>" + item.PatientId + "</td>" +
                "<td width='100'>累计费用总额：</td>" +
                "<td width='100' id='InMoney'>" + item.InMoney + " </td>" +
                "<td width='100'>丙类费用总额：</td>" +
                "<td width='100' id='blmoney'>" + item.blmoney + "</td>" +
                "<td width='100'>丙类占比：</td>" +
                "<td width='100' id='Blbl'> " + (item.Blbl * 100).toFixed(2) + "%</td>");
            var tr3 = $("<tr></tr>");
            $(".detailWindow .detailBody .ruleInfo table").append(tr3);
            tr3.append("<td>住院号：</td><td>" + item.inpcode + "</td><td>主治医生：</td><td>" + item.Doctorname + "</td><td>入院时间：</td><td colspan='3'>" + item.dinhos + "</td>");
            var tr1 = $("<tr></tr>");
            $(".detailWindow .detailBody .ruleInfo table").append(tr1);
            tr1.append("<td>所属科室：</td><td>" + item.DeptName + "</td><td>诊断疾病：</td><td colspan='5'>" + item.Icd10Name + "</td>");

            clearDetailWindow();
            var tableGroup = $("<div class='tableGroups'></div>");
            $(".detailWindow .detailBody").append(tableGroup);
            //费用明细
            var group = getGroupObj("科室丙类费用统计");
            tableGroup.append(group);
            loadServerData("/quality/poor/queryDeptList/" + item.PatientId, null, function (data) {
                for (var i = 0; i < data.datas.length;) {
                    var tr = $("<tr></tr>");
                    group.find("table").append(tr);
                    for (var j = 0; j < 1; j++) {
                        if (i < data.datas.length) {
                            tr.append($("<td>" + data.datas[i].DeptName +
                                "</td><td>丙类金额：" + data.datas[i].BlMoney +
                                "</td><td>总金额：" + data.datas[i].TotalMoney +
                                "</td><td>丙类占比：" + (data.datas[i].BlMoney / data.datas[i].TotalMoney * 100).toFixed(2) + "%" +
                                "</td>"));
                            i++;
                        } else {
                            break;
                        }
                    }
                }
            })

            var tableGroup1 = $("<div class='tableGroups'></div>");
            $(".detailWindow .detailBody").append(tableGroup1);
            var group1 = getGroupObj("甲类费用");
            tableGroup1.append(group1);
            loadServerData("/quality/poor/queryPKFareDetail/" + item.PatientId + "/1", null, function (data) {
                for (var i = 0; i < data.datas.length;) {
                    var tr = $("<tr></tr>");
                    group1.find("table").append(tr);
                    for (var j = 0; j < 1; j++) {
                        if (i < data.datas.length) {
                            tr.append($("<td>" + data.datas[i].DeptName +
                                "</td><td>" + data.datas[i].FareItemName +
                                "</td><td>金额：" + (data.datas[i].InMoney / data.datas[i].Quantity).toFixed(2) +
                                "</td><td>×" + data.datas[i].Quantity.toFixed(0) + "" +
                                "</td><td>" + (data.datas[i].InMoney).toFixed(2) + "" +
                                "</td>"));
                            i++;
                        } else {
                            break;
                        }
                    }
                }
            })

            var tableGroup2 = $("<div class='tableGroups'></div>");
            $(".detailWindow .detailBody").append(tableGroup2);
            var group2 = getGroupObj("乙类费用");
            tableGroup2.append(group2);
            loadServerData("/quality/poor/queryPKFareDetail/" + item.PatientId + "/2", null, function (data) {
                for (var i = 0; i < data.datas.length;) {
                    var tr = $("<tr></tr>");
                    group2.find("table").append(tr);
                    for (var j = 0; j < 1; j++) {
                        if (i < data.datas.length) {
                            tr.append($("<td>" + data.datas[i].DeptName +
                                "</td><td>" + data.datas[i].FareItemName +
                                "</td><td>金额：" + (data.datas[i].InMoney / data.datas[i].Quantity).toFixed(2) +
                                "</td><td>×" + data.datas[i].Quantity.toFixed(0) + "" +
                                "</td><td>" + (data.datas[i].InMoney).toFixed(2) + "" +
                                "</td>"));
                            i++;
                        } else {
                            break;
                        }
                    }
                }
            })
            var tableGroup3 = $("<div class='tableGroups'></div>");
            $(".detailWindow .detailBody").append(tableGroup3);
            var group3 = getGroupObj("丙类费用");
            tableGroup3.append(group3);
            $(".detailWindow .detailFoot .info").html("删除丙类金额：<span id='selectValue'>0.00</span> 转换丙类金额：<span id='replyValue'>0.00</span>");
            loadServerData("/quality/poor/queryPKFareDetail/" + item.PatientId + "/3", null, function (data) {
                for (var i = 0; i < data.datas.length;) {
                    var tr = $("<tr value='" + (data.datas[i].InMoney ) + "'></tr>");
                    group3.find("table").append(tr);
                    for (var j = 0; j < 1; j++) {
                        if (i < data.datas.length) {
                            tr.append($("<td>" + data.datas[i].DeptName +
                                "</td><td>" + data.datas[i].FareItemName +
                                "</td><td>金额：" + (data.datas[i].InMoney / data.datas[i].Quantity).toFixed(2) +
                                "</td><td>×" + data.datas[i].Quantity.toFixed(0) + "" +
                                "</td><td>" + (data.datas[i].InMoney).toFixed(2) + "" +
                                "</td><td><span class='am-icon-reply myLink' id='reply'> 转换为甲类</span>" +
                                "</td>"));
                            i++;
                        } else {
                            break;
                        }
                    }
                    tr.on("click", function (e) {
                        var row = $(e.target).parents("tr");
                        var val = row.attr("value");
                        if (val == null) return;
                        if (row.hasClass("replyRow")){
                            var span=row.find("#reply");
                            span.html(" 转换为甲类")
                            span.removeClass("am-icon-share");
                            span.addClass("am-icon-reply");
                            row.removeClass("replyRow");
                            val *= -1;
                            var InMoney = $(".detailWindow .detailBody #InMoney");
                            var blmoney = $(".detailWindow .detailBody #blmoney");
                            var Blbl = $(".detailWindow .detailBody #Blbl");
                            var replyValueD = $(".detailWindow .detailFoot #replyValue");
                            var inM = InMoney.html().trim();
                            var blM = blmoney.html().trim();
                            var replyValue = replyValueD.html().trim();
                            blM = blM * 1 - (val * 1);
                            inM = inM * 1 ;
                            replyValue = replyValue * 1 + (val * 1);
                            blmoney.html((blM).toFixed(2)).css({
                                "font-weight": "800",
                                "color": "#c30303",
                                "font-size": "1.2em"
                            });
                            InMoney.html((inM).toFixed(2)).css({
                                "font-weight": "800",
                                "color": "#c30303",
                                "font-size": "1.2em"
                            });
                            Blbl.html(((blM / inM) * 100).toFixed(2) + "%").css({
                                "font-weight": "800",
                                "color": "#c30303",
                                "font-size": "1.2em"
                            });
                            $(".detailWindow .detailFoot #replyValue").html( replyValue.toFixed(2) );
                            val *= -1;
                        }
                        if (row.attr("delete") == "1") {
                            row.attr("delete", "0");
                            row.removeClass("deleteRow");
                            val *= -1;
                        } else {
                            row.attr("delete", "1");
                            row.addClass("deleteRow");
                            val *= 1;
                        }
                        var InMoney = $(".detailWindow .detailBody #InMoney");
                        var blmoney = $(".detailWindow .detailBody #blmoney");
                        var Blbl = $(".detailWindow .detailBody #Blbl");
                        var selectValueD = $(".detailWindow .detailFoot #selectValue");
                        var inM = InMoney.html().trim();
                        var blM = blmoney.html().trim();
                        var selectValue = selectValueD.html().trim();
                        blM = blM * 1 - (val * 1);
                        inM = inM * 1 - (val * 1);
                        selectValue = selectValue * 1 + (val * 1);
                        blmoney.html((blM).toFixed(2)).css({
                            "font-weight": "800",
                            "color": "#c30303",
                            "font-size": "1.2em"
                        });
                        InMoney.html((inM).toFixed(2)).css({
                            "font-weight": "800",
                            "color": "#c30303",
                            "font-size": "1.2em"
                        });
                        Blbl.html(((blM / inM) * 100).toFixed(2) + "%").css({
                            "font-weight": "800",
                            "color": "#c30303",
                            "font-size": "1.2em"
                        });
                        $(".detailWindow .detailFoot #selectValue").html( selectValue.toFixed(2) );


                    })

                    tr.on("click", "#reply", function (e) {
                        var row = $(e.target).parents("tr");
                        var val = row.attr("value");
                        if (val == null) return;
                        //如果已经是删除的数据则恢复为正常数据
                        if (row.attr("delete") == "1") {
                            row.attr("delete", "0");
                            row.removeClass("deleteRow");
                            val *= -1;
                            var InMoney = $(".detailWindow .detailBody #InMoney");
                            var blmoney = $(".detailWindow .detailBody #blmoney");
                            var Blbl = $(".detailWindow .detailBody #Blbl");
                            var selectValueD = $(".detailWindow .detailFoot #selectValue");
                            var inM = InMoney.html().trim();
                            var blM = blmoney.html().trim();
                            var selectValue = selectValueD.html().trim();
                            blM = blM * 1 - (val * 1);
                            inM = inM * 1 - (val * 1);
                            selectValue = selectValue * 1 + (val * 1);
                            blmoney.html((blM).toFixed(2)).css({
                                "font-weight": "800",
                                "color": "#c30303",
                                "font-size": "1.2em"
                            });
                            InMoney.html((inM).toFixed(2)).css({
                                "font-weight": "800",
                                "color": "#c30303",
                                "font-size": "1.2em"
                            });
                            Blbl.html(((blM / inM) * 100).toFixed(2) + "%").css({
                                "font-weight": "800",
                                "color": "#c30303",
                                "font-size": "1.2em"
                            });
                            $(".detailWindow .detailFoot #selectValue").html( selectValue.toFixed(2) );
                            val *= -1;
                        }
                        var span=$(e.target);
                        if(span.hasClass("am-icon-reply")){
                            span.html(" 恢复为丙类")
                            span.removeClass("am-icon-reply");
                            span.addClass("am-icon-share");
                            val *= 1;
                            row.addClass("replyRow");
                        }else{
                            span.html(" 转换为甲类")
                            span.removeClass("am-icon-share");
                            span.addClass("am-icon-reply");
                            val *= -1;
                            row.removeClass("replyRow");
                        }

                        var InMoney = $(".detailWindow .detailBody #InMoney");
                        var blmoney = $(".detailWindow .detailBody #blmoney");
                        var Blbl = $(".detailWindow .detailBody #Blbl");
                        var replyValueD = $(".detailWindow .detailFoot #replyValue");
                        var inM = InMoney.html().trim();
                        var blM = blmoney.html().trim();
                        var replyValue = replyValueD.html().trim();
                        blM = blM * 1 - (val * 1);
                        inM = inM * 1 ;
                        replyValue = replyValue * 1 + (val * 1);
                        blmoney.html((blM).toFixed(2)).css({
                            "font-weight": "800",
                            "color": "#c30303",
                            "font-size": "1.2em"
                        });
                        InMoney.html((inM).toFixed(2)).css({
                            "font-weight": "800",
                            "color": "#c30303",
                            "font-size": "1.2em"
                        });
                        Blbl.html(((blM / inM) * 100).toFixed(2) + "%").css({
                            "font-weight": "800",
                            "color": "#c30303",
                            "font-size": "1.2em"
                        });
                        $(".detailWindow .detailFoot #replyValue").html( replyValue.toFixed(2) );

                        e.stopPropagation();
                    })
                }
            })
            setTabPage([tableGroup, tableGroup1, tableGroup2, tableGroup3]);
        });


    }, "#pkList2");


}

//单病种
function dbzCount() {
    var boxId = "#dbz";
    loadServerData("/quality/drgs/queryCount/1/0", {}, function (data) {
        var error1 = data.datas[0].countError;
        var all1 = data.datas[0].countAll;
        $(boxId + " #error1").html(error1);
        $(boxId + " #all1").html(all1);
        $(boxId + " #sumError").html($(boxId + " #error1").html() * 1 + $(boxId + " #error2").html() * 1);
        $(boxId + " #sumAll").html($(boxId + " #all1").html() * 1 + $(boxId + " #all2").html() * 1);
        $(boxId + " .infoBar").css("width", $(boxId + " #sumError").html() / $(boxId + " #sumAll").html() * 100 + "%");
        $(boxId + " .listBar").css("width", $(boxId + " #sumError").html() / $(boxId + " #sumAll").html() * 100 + "%");
    });
    loadServerData("/quality/drgs/queryCount/2/0", {}, function (data) {
        var error2 = data.datas[0].countError;
        var all2 = data.datas[0].countAll;
        $(boxId + " #error2").html(error2);
        $(boxId + " #all2").html(all2);
        $(boxId + " #sumError").html($(boxId + " #error1").html() * 1 + $(boxId + " #error2").html() * 1);
        $(boxId + " #sumAll").html($(boxId + " #all1").html() * 1 + $(boxId + " #all2").html() * 1);
        $(boxId + " .infoBar").css("width", $(boxId + " #sumError").html() / $(boxId + " #sumAll").html() * 100 + "%");
        $(boxId + " .listBar").css("width", $(boxId + " #sumError").html() / $(boxId + " #sumAll").html() * 100 + "%");
    });
    $(boxId + " .more").bind("click", function () {
        top.addTabs({
            id: "pkrkZK",
            title: "单病种质控",
            close: true,
            url: "/quality/drgs"
        })
    });

    loadServerData("/quality/drgs/queryAllPager", {
        ybType: 1,
        pageNum: 1,
        error: true,
        pageSize: 10
    }, function (data) {


        loadPager(data.datas, "dbzList1", [{
            data: "DeptName"
        }, {
            data: "Name"
        }, {
            hide: true,
            data: "Icd10Name"
        }, {
            render: function (data) {
                return data.InMoney + "元";
            }
        }], function (item) {
            showDetail();
            $(".detailWindow .title").html("单病种质控");
            $(".detailWindow .subTitle").html("就诊人姓名：" + item.Name + "<span>省医保</span>");
            $(".detailWindow .detailBody .ruleInfo").html("<table border=0 cellpadding=0 cellspacing=0></table>");
            // $(".detailWindow .detailBody .ruleInfo").append("<div class='ruleTitle'>就诊人信息</div>");
            var tr2 = $("<tr></tr>");
            $(".detailWindow .detailBody .ruleInfo table").append(tr2);
            tr2.append("<td width='100'>累计费用：</td>" +
                "<td width='100'>" + item.InMoney + "</td>" +
                "<td width='100'> </td>" +
                "<td width='100'> </td>"
                // "<td width='100'>丙类药占比：</td>" +
                // "<td width='100'>" + (item.Blbl * 100).toFixed(1) + "%</td>" +
                // "<td width='100'>标准占比：</td>" +
                // "<td width='100'> " + item.Threshold * 100 + "%</td>"
            );
            var tr3 = $("<tr></tr>");
            $(".detailWindow .detailBody .ruleInfo table").append(tr3);
            tr3.append("<td>主治医生：</td><td>" + item.Doctorname + "</td><td>违规时间：</td><td colspan='5'>" + item.CreateDate + "</td>");
            var tr1 = $("<tr></tr>");
            $(".detailWindow .detailBody .ruleInfo table").append(tr1);
            tr1.append("<td>所属科室：</td><td>" + item.DeptName + "</td><td>诊断疾病：</td><td colspan='5'>" + item.Icd10Name + "</td>");

            clearDetailWindow();
            var tableGroup = $("<div class='tableGroups'></div>");
            $(".detailWindow .detailBody").append(tableGroup);
            //费用明细
            var group = getGroupObj("违规明细");
            tableGroup.append(group);
            loadServerData("/quality/drgs/queryDetailList/" + item.PatientId, null, function (data) {
                for (var i = 0; i < data.datas.length;) {
                    var tr = $("<tr></tr>");
                    group.find("table").append(tr);
                    for (var j = 0; j < 1; j++) {
                        if (i < data.datas.length) {
                            tr.append($("<td>当前总金额：" + data.datas[i].nmoney +
                                "</td><td>总金额定额：" + data.datas[i].nfixedmoney +
                                "</td><td>费用分类名称：" + data.datas[i].fareclassname +
                                "</td><td>" + data.datas[i].intime +
                                "</td><td>" + "金额超限" +
                                "</td><td>" + "医生同意继续执行" +
                                "</td>"));
                            i++;
                        } else {
                            break;
                        }
                    }
                }
            })
        });

    });

    loadServerData("/quality/drgs/queryAllPager", {
        ybType: 2,
        pageNum: 1,
        error: true,
        pageSize: 10
    }, function (data) {


        loadPager(data.datas, "dbzList2", [{
            data: "DeptName"
        }, {
            data: "Name"
        }, {
            hide: true,
            data: "Icd10Name"
        }, {
            render: function (data) {
                return data.InMoney + "元";
            }
        }], function (item) {
            showDetail();
            $(".detailWindow .title").html("单病种质控");
            $(".detailWindow .subTitle").html("就诊人姓名：" + item.Name + "<span>省医保</span>");
            $(".detailWindow .detailBody .ruleInfo").html("<table border=0 cellpadding=0 cellspacing=0></table>");
            // $(".detailWindow .detailBody .ruleInfo").append("<div class='ruleTitle'>就诊人信息</div>");
            var tr2 = $("<tr></tr>");
            $(".detailWindow .detailBody .ruleInfo table").append(tr2);
            tr2.append("<td width='100'>累计费用：</td>" +
                "<td width='100'>" + item.InMoney + "</td>" +
                "<td width='100'> </td>" +
                "<td width='100'> </td>"
                // "<td width='100'>丙类药占比：</td>" +
                // "<td width='100'>" + (item.Blbl * 100).toFixed(1) + "%</td>" +
                // "<td width='100'>标准占比：</td>" +
                // "<td width='100'> " + item.Threshold * 100 + "%</td>"
            );
            var tr3 = $("<tr></tr>");
            $(".detailWindow .detailBody .ruleInfo table").append(tr3);
            tr3.append("<td>主治医生：</td><td>" + item.Doctorname + "</td><td>违规时间：</td><td colspan='5'>" + item.CreateDate + "</td>");
            var tr1 = $("<tr></tr>");
            $(".detailWindow .detailBody .ruleInfo table").append(tr1);
            tr1.append("<td>所属科室：</td><td>" + item.DeptName + "</td><td>诊断疾病：</td><td colspan='5'>" + item.Icd10Name + "</td>");

            clearDetailWindow();
            var tableGroup = $("<div class='tableGroups'></div>");
            $(".detailWindow .detailBody").append(tableGroup);
            //费用明细
            var group = getGroupObj("违规明细");
            tableGroup.append(group);
            loadServerData("/quality/drgs/queryDetailList/" + item.PatientId, null, function (data) {
                for (var i = 0; i < data.datas.length;) {
                    var tr = $("<tr></tr>");
                    group.find("table").append(tr);
                    for (var j = 0; j < 1; j++) {
                        if (i < data.datas.length) {
                            tr.append($("<td>当前总金额：" + data.datas[i].nmoney +
                                "</td><td>总金额定额：" + data.datas[i].nfixedmoney +
                                "</td><td>费用分类名称：" + data.datas[i].fareclassname +
                                "</td><td>" + data.datas[i].intime +
                                "</td><td>" + "金额超限" +
                                "</td><td>" + "医生同意继续执行" +
                                "</td>"));
                            i++;
                        } else {
                            break;
                        }
                    }
                }
            })
        });

    });

}

//慢病
function mbCount() {
    var boxId = "#mb";
    loadServerData("/quality/chronic/queryCount/1/0", {}, function (data) {
        var error1 = data.datas[0].countError;
        var all1 = data.datas[0].countAll;
        $(boxId + " #error1").html(error1);
        $(boxId + " #all1").html(all1);
        $(boxId + " #sumError").html($(boxId + " #error1").html() * 1 + $(boxId + " #error2").html() * 1);
        $(boxId + " #sumAll").html($(boxId + " #all1").html() * 1 + $(boxId + " #all2").html() * 1);
        $(boxId + " .infoBar").css("width", $(boxId + " #sumError").html() / $(boxId + " #sumAll").html() * 100 + "%");
        $(boxId + " .listBar").css("width", $(boxId + " #sumError").html() / $(boxId + " #sumAll").html() * 100 + "%");
    });
    loadServerData("/quality/chronic/queryCount/2/0", {}, function (data) {
        var error2 = data.datas[0].countError;
        var all2 = data.datas[0].countAll;
        $(boxId + " #error2").html(error2);
        $(boxId + " #all2").html(all2);
        $(boxId + " #sumError").html($(boxId + " #error1").html() * 1 + $(boxId + " #error2").html() * 1);
        $(boxId + " #sumAll").html($(boxId + " #all1").html() * 1 + $(boxId + " #all2").html() * 1);
        $(boxId + " .infoBar").css("width", $(boxId + " #sumError").html() / $(boxId + " #sumAll").html() * 100 + "%");
        $(boxId + " .listBar").css("width", $(boxId + " #sumError").html() / $(boxId + " #sumAll").html() * 100 + "%");
    });
    $(boxId + " .more").bind("click", function () {
        top.addTabs({
            id: "pkrkZK",
            title: "慢病就诊人质控",
            close: true,
            url: "/quality/drgs"
        })
    });

    loadServerData("/quality/chronic/queryAllPager", {
        ybType: 1,
        pageNum: 1,
        error: true,
        pageSize: 10
    }, function (data) {

        loadPager(data.datas, "mbList1", [{
            data: "DeptName"
        }, {
            data: "Name"
        }, {
            hide: true,
            data: "Icd10Name"
        }, {
            render: function (data) {
                return "本次" + data.InMoney + "元";
            }
        }, {
            render: function (data) {
                return "本月" + data.InMonthMoney + "元";
            }
        }], function (item) {
            showDetail();
            $(".detailWindow .title").html("慢病就诊人质控");
            $(".detailWindow .subTitle").html("就诊人姓名：" + item.Name + "<span>省医保</span>");
            $(".detailWindow .detailBody .ruleInfo").html("<table border=0 cellpadding=0 cellspacing=0></table>");
            // $(".detailWindow .detailBody .ruleInfo").append("<div class='ruleTitle'>就诊人信息</div>");
            var tr2 = $("<tr></tr>");
            $(".detailWindow .detailBody .ruleInfo table").append(tr2);
            tr2.append("<td width='100'>累计费用：</td>" +
                "<td width='100'>" + item.InMoney + "</td>" +
                "<td width='100'> </td>" +
                "<td width='100'> </td>"
                // "<td width='100'>丙类药占比：</td>" +
                // "<td width='100'>" + (item.Blbl * 100).toFixed(1) + "%</td>" +
                // "<td width='100'>标准占比：</td>" +
                // "<td width='100'> " + item.Threshold * 100 + "%</td>"
            );
            var tr3 = $("<tr></tr>");
            $(".detailWindow .detailBody .ruleInfo table").append(tr3);
            tr3.append("<td>主治医生：</td><td>" + item.Doctorname + "</td><td>违规时间：</td><td colspan='5'>" + item.CreateDate + "</td>");
            var tr1 = $("<tr></tr>");
            $(".detailWindow .detailBody .ruleInfo table").append(tr1);
            tr1.append("<td>所属科室：</td><td>" + item.DeptName + "</td><td>诊断疾病：</td><td colspan='5'>" + item.Icd10Name + "</td>");

            clearDetailWindow();
            var tableGroup = $("<div class='tableGroups'></div>");
            $(".detailWindow .detailBody").append(tableGroup);
            //费用明细
            var group = getGroupObj("违规明细");
            tableGroup.append(group);
            loadServerData("/quality/chronic/queryDetailList/" + item.PatientId, null, function (data) {
                for (var i = 0; i < data.datas.length;) {
                    var tr = $("<tr></tr>");
                    group.find("table").append(tr);
                    for (var j = 0; j < 1; j++) {
                        if (i < data.datas.length) {
                            tr.append($("<td>" + data.datas[i].cdrugname +
                                "</td><td>" + data.datas[i].nthismoney + "元" +
                                "</td><td>上次开药时间：" + data.datas[i].lasttime +
                                "</td><td>上次开药天数：" + data.datas[i].idays +
                                "</td><td>" + data.datas[i].intime +
                                "</td><td>" + "超限" +
                                "</td><td>" + "医生同意继续执行" +
                                "</td>"));
                            i++;
                        } else {
                            break;
                        }
                    }
                }
            })
        });

    });
    loadServerData("/quality/chronic/queryAllPager", {
        ybType: 2,
        pageNum: 1,
        error: true,
        pageSize: 10
    }, function (data) {

        loadPager(data.datas, "mbList2", [{
            data: "DeptName"
        }, {
            data: "Name"
        }, {
            hide: true,
            data: "Icd10Name"
        }, {
            render: function (data) {
                return "本次" + data.InMoney + "元";
            }
        }, {
            render: function (data) {
                return "本月" + data.InMonthMoney + "元";
            }
        }], function (item) {
            showDetail();
            $(".detailWindow .title").html("慢病就诊人质控");
            $(".detailWindow .subTitle").html("就诊人姓名：" + item.Name + "<span>省医保</span>");
            $(".detailWindow .detailBody .ruleInfo").html("<table border=0 cellpadding=0 cellspacing=0></table>");
            // $(".detailWindow .detailBody .ruleInfo").append("<div class='ruleTitle'>就诊人信息</div>");
            var tr2 = $("<tr></tr>");
            $(".detailWindow .detailBody .ruleInfo table").append(tr2);
            tr2.append("<td width='100'>累计费用：</td>" +
                "<td width='100'>" + item.InMoney + "</td>" +
                "<td width='100'> </td>" +
                "<td width='100'> </td>"
                // "<td width='100'>丙类药占比：</td>" +
                // "<td width='100'>" + (item.Blbl * 100).toFixed(1) + "%</td>" +
                // "<td width='100'>标准占比：</td>" +
                // "<td width='100'> " + item.Threshold * 100 + "%</td>"
            );
            var tr3 = $("<tr></tr>");
            $(".detailWindow .detailBody .ruleInfo table").append(tr3);
            tr3.append("<td>主治医生：</td><td>" + item.Doctorname + "</td><td>违规时间：</td><td colspan='5'>" + item.CreateDate + "</td>");
            var tr1 = $("<tr></tr>");
            $(".detailWindow .detailBody .ruleInfo table").append(tr1);
            tr1.append("<td>所属科室：</td><td>" + item.DeptName + "</td><td>诊断疾病：</td><td colspan='5'>" + item.Icd10Name + "</td>");

            clearDetailWindow();
            var tableGroup = $("<div class='tableGroups'></div>");
            $(".detailWindow .detailBody").append(tableGroup);
            //费用明细
            var group = getGroupObj("违规明细");
            tableGroup.append(group);
            loadServerData("/quality/chronic/queryDetailList/" + item.PatientId, null, function (data) {
                for (var i = 0; i < data.datas.length;) {
                    var tr = $("<tr></tr>");
                    group.find("table").append(tr);
                    for (var j = 0; j < 1; j++) {
                        if (i < data.datas.length) {
                            tr.append($("<td>" + data.datas[i].cdrugname +
                                "</td><td>" + data.datas[i].nthismoney + "元" +
                                "</td><td>上次开药时间：" + data.datas[i].lasttime +
                                "</td><td>上次开药天数：" + data.datas[i].idays +
                                "</td><td>" + data.datas[i].intime +
                                "</td><td>" + "超限" +
                                "</td><td>" + "医生同意继续执行" +
                                "</td>"));
                            i++;
                        } else {
                            break;
                        }
                    }
                }
            })
        });

    });

}

function loadPager(data, box, columns, detail) {
    var pageSize = 7;
    var pageCount = Math.ceil(data.length / pageSize);

    var content = $("#" + box + " .pagerInfo span");
    content.html("<font>1</font>/" + pageCount);
    var prev = $("<a>上一页</a>")
    var next = $("<a>下一页</a>")
    content.append(prev).append(next);

    loadPagerData(data, box, 1, columns, detail);

    prev.bind("click", function () {
        var nowPage = content.find("font").html() - 1;
        if (nowPage != 0) {
            loadPagerData(data, box, nowPage, columns, detail);
        }
    })

    next.bind("click", function () {
        var nowPage = content.find("font").html() * 1 + 1;
        if (nowPage <= pageCount) {
            loadPagerData(data, box, nowPage, columns, detail);
        }
    })
}

function loadPagerData(data, box, page, columns, detail) {
    $("#" + box + " .pagerInfo font").html(page);

    var table = $("#" + box + " table");
    table.html("");

    $(data).each(function (i, item) {
        if (i >= (page - 1) * 7 && i < (page) * 7) {
            var tr = $("<tr></tr>");
            tr.bind("click", function () {
                detail(item);
            })
            table.append(tr);
            for (var j = 0; j < columns.length; j++) {
                var td = $("<td></td>");
                tr.append(td);
                if (columns[j].render != null) {
                    td.append(columns[j].render(item));
                } else {
                    td.append(item[columns[j].data]);
                }
                td.attr("title", item[columns[j].data]);
                if (columns[j].hide) {
                    td.addClass("hide");
                    if ($(".max").hasClass("am-icon-eye")) {
                        td.css("display", "none");
                    } else {
                        td.css("display", "table-cell");
                    }
                }
            }
        }
    })
}

function setTabPage(groups) {
    var tabPage = $("<div class='tabPage'></div>")
    var buttons = $("<div class='tabButtons'></div>")
    var pages = $("<div class='tabPages'></div>")
    tabPage.append(buttons).append(pages);
    groups[0].before(tabPage);
    $(groups).each(function (index, item) {
        buttons.append(item.find(".groupName"));
        pages.append(item.find(".group"));
        item.remove();
    });
    bindTab(buttons, "groupName", pages);
}

function clearDetailWindow() {
    $(".detailWindow .detailBody .tableGroups").remove();
    $(".detailWindow .detailBody .tabPage").remove();
    $(".detailWindow .detailFoot .info").html("");
}